﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OKDebug
{
    public partial class FrmPLCMNAdd : Form
    {
        public PLCMN _pLCMN;
        public int _rowIndex;
        public event EventHandler OnOK = null;
        public FrmPLCMNAdd()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text.Trim()))
            {
                txtName.Focus();
                MessageBox.Show("名称为空!");
                return;
            }

            if (string.IsNullOrEmpty(txtAddress.Text.Trim()))
            {
                txtAddress.Focus();
                MessageBox.Show("地址为空!");
                return;
            }

            PLCAddrVal pLCAddrVal = new PLCAddrVal();
            pLCAddrVal.Name = txtName.Text.Trim();
            pLCAddrVal.Addr = txtAddress.Text.Trim();
            pLCAddrVal.Type = cbxType.SelectedItem.ToString();
            pLCAddrVal.Length = txtLength.Text.Trim();
            pLCAddrVal.Val = txtVal.Text.Trim();
            _pLCMN.PLCAddrValList.Insert(_rowIndex+1,pLCAddrVal);
            if (OnOK != null)
            {
                OnOK(null,null);
            }

            Close();
        }
    }
}
